<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
</head>
<body>
<div class="ibox-content">
		<form class="form-horizontal" id="dataform" onsubmit="javascripr:return false;">
			<input type="hidden" name="tokenUrl" value="${tokenUrl}">	 
			<input type="hidden" name="token" value="${token}">
		<c:if test="${obj ne null }">
			<input type="hidden" name="menId" value="${menId }">
		</c:if>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">添加菜谱
			<span class="text-danger">*</span>
			</label>
			<div class="col-sm-4">
				<button class=" btn btn-success btn-sm" id="btn_addtr" type="button" >添加</button>
			</div>
		</div>
		<div class="form-group" id="groupDiv">	
		<c:forEach var='menu' items="${menuList }" varStatus="s">
		<input type="hidden" name="menuManages[${s.index}].detailMenId" value="${menu.detailMenId}">
	
		<div class="form-group" id="div${s.index+1}">	
			<label class="col-sm-2 control-label">菜名
			<span class="text-danger">*</span>
			</label>
			<div class="col-sm-4">
			<select class="form-control autoFull select2" dataType="*" nullmsg="菜谱类别不能为空" 
					data-url="${path}/admin/pcMenuManage/all"
					data-value="menId"
					data-filed="menName"
					data-def="${menu.menId}"  
					name="menuManages[${s.index}].menId">
					
			</select>		
			</div>
			 <button onclick="deleTr(this)" class=" btn btn-success btn-sm" id="btn_del" 
	           	 type="button" >删除</button>
		</div>	
		</c:forEach>
		</div>	
		
		<div class="form-group ">
			<div class="col-sm-12 text-center">
				<a href="javascript:;" onclick="myForm.submit()"
					class="btn btn-success radius"><i class="fa fa-check"></i>  保存</a>&nbsp;&nbsp;&nbsp;&nbsp; <a
					 class="btn btn-danger radius" href="javascript:;" onclick="MTools.closeForm()" ><i class="fa fa-close"></i> 关闭</a>
			</div>
		</div>
	</form>
	</div>
</body>
<script type="text/javascript" src="${path }/resource/js/systools/MJsBase.js"></script>
<script type="template" id="template">
	<div class="form-group" id="divId">	
			<label class="col-sm-2 control-label">菜名
			<span class="text-danger">*</span>
			</label>
			<div class="col-sm-4">
			<select class="form-control autoFull select2" dataType="*" nullmsg="菜谱类别不能为空" id="menuId"
					data-url="${path}/admin/pcMenuManage/all"
					data-value="menId"
					data-filed="menName"
					data-def=""  
					name="nameId">
			</select>	
				<span class="Validform_checktip"></span>	
			</div>
			 <button onclick="deleTr(this)" class=" btn btn-success btn-sm" id="btn_del" 
	           	 type="button" >删除</button>
		</div>	
</script>
<script type="text/javascript">
	MTools.autoFullSelect();
	$(".select2").select2();
	var myForm=MForm.initForm({
		invokeUrl:"${path}/admin/pcMenuDetail/addOrModify-food",
		beforeSubmit:function(){
			//提交之前判断菜谱值是否有重复
			var n=parseInt($(".autoFull").length);
			if(n==0){
				layer.msg("选择至少一个菜", {
					icon : 2,time:1000
				});
				return false;
			}
			var arr=new Array(n);
			for(var j=0 ;j<n ;j++){
				for(var i=0 ; i<arr.length ; i++ ){
					if(arr[i]==$(".autoFull").eq(j).val()){
						layer.msg("菜名重复", {
							icon : 2,time:1000
						});
						return false;
					}
				}
				arr[j]=$(".autoFull").eq(j).val();
			}
		}, 
		afterSubmit:function(){
			//刷新list页面数据
			parent.app.showData();
		},
	});
	var num;
	$(function(){
		num=parseInt($(".autoFull").size());
		$("#btn_addtr").click(function(){
			num++;
			 $('#groupDiv').append($("#template").html().replace('nameId','menuManages['+num+'].menId')
					 .replace('divId','div'+num)	 
					 .replace('menuId','menuId'+num)	
			 );
			 MTools.autoFullSelect("#menuId"+num); 	
				$("#menuId"+num).select2({width:"100%"});
		});
	});
	function deleTr(node){
		$(node).parent('div').remove();
	}
			
</script>
</body>
</html>